import 'package:flutter/material.dart';
import 'routes/app_routes.dart';
import 'utils/deferred_router.dart';

void main() {
  // 初始化路由
  AppRoutes.initialize();
  
  // 设置预加载策略
  SmartPreloadManager.setStrategy(PreloadStrategy.hybrid);
  SmartPreloadManager.setCriticalRoutes({'home'});
  
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    // 执行智能预加载策略
    _executePreloadStrategy();
  }

  Future<void> _executePreloadStrategy() async {
    try {
      await SmartPreloadManager.executePreloadStrategy();
    } catch (e) {
      debugPrint('Preload strategy execution failed: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Deferred Router Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      routerConfig: AppRoutes.router,
    );
  }
}